/*
 * @lc app=leetcode.cn id=228 lang=csharp
 *
 * [228] 汇总区间
 */

// @lc code=start
public class Solution {
    public IList<string> SummaryRanges(int[] nums) {
        var ans = new List<string>();
        int i = 0;
        int n = nums.Length;
        while (i < n) {
            int low = i;
            i++;
            while (i < n && nums[i] == nums[i - 1] + 1) {
                i++;
            }
            int high = i - 1;
            StringBuilder temp = new StringBuilder(nums[low].ToString());
            if (low < high) {
                temp.Append("->");
                temp.Append(nums[high].ToString());
            }
            ans.Add(temp.ToString());
        }
        return ans;
    }
}
// @lc code=end

